﻿#include "GnsClientFrame.h"
#include "GNS_LoginScene.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
#include "GNS_PlayerMgr.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"
#include "GNS_Common.h"
#include "SystemMgr.h"	

extern GNS_HallScene* _hallScene;

bool GNS_LoginScene::bRegist = false;

USING_NS_CC;
using namespace cocostudio::timeline;
using namespace ui;

#define winsize Director::getInstance()->getVisibleSize()


enum
{
	BTN_TIPS_SUBMIT = 0,
	START_TAG_BTN = 1,
	REG_TAG_BTN = 2,
	REG_TAG_Y = 3,
	REG_TAG_N = 4,
	BTN_GUSET,         //游客登录
	BTN_SUBMIT_UPDATA,   //确定升级
	BTN_QX_UPDATA,  //取消升级

	BTN_KEFU,  //客服
};


GNS_LoginScene::GNS_LoginScene()
{
}

GNS_LoginScene::~GNS_LoginScene()
{
}

Scene* GNS_LoginScene::createScene()
{
    // 'scene' is an autorelease object
    auto scene = Scene::create();
    
    // 'layer' is an autorelease object
	auto layer = GNS_SceneMgr::getInstance()->AddSceneLayer(LAYER_LOGIN);

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool GNS_LoginScene::init()
{
    //////////////////////////////
    // 1. super init first
	AddKeyboard(true);
    if ( !GNS_YJFLayer::init() )
    {
        return false;
    }
	//initTipsWnd("w.png","tips");

	unsigned short part = 6100;
	//GNS_ClientLogin::getInstance()->connect(IP,part);

	int version = VER_MAIN * 100000 +
		VER_CHILD * 10000 +
		VER_BUILD;

	GNS_PlayerMgr::GetInstance()->setCurrentVersionClient(version);

    auto rootNode = Loadcsb("MainScenes/LoginScene.csb");
	rootNode->setPosition(Vec2(winsize.width/2,winsize.height/2));
    addChild(rootNode,0,10);

	auto textVersion = (Text*)rootNode->getChildByName("Text_1");
	textVersion->setTextColor(Color4B::YELLOW);
	textVersion->setString(StringUtils::format("V%d", version));

	auto kefuBtn = (Button*)rootNode->getChildByName("Button_4");		//客服按钮
	kefuBtn->setTag(BTN_KEFU);
	kefuBtn->addTouchEventListener(CC_CALLBACK_2(GNS_LoginScene::BtnCallBack,this));

    
    
    auto rootNode1 =Loadcsb("MainScenes/LoginLayer.csb");
	rootNode1->setPosition(Vec2(winsize.width / 2, winsize.height / 2));
    addChild(rootNode1,1,11);
    rootNode1->setVisible(false);
    
    StartBtn = static_cast<ui::Button*>(rootNode->getChildByName("Button_start"));
	StartBtn->addTouchEventListener(CC_CALLBACK_2(GNS_LoginScene::BtnCallBack, this));
    StartBtn->setTag(START_TAG_BTN);
	//StartBtn->setVisible(false);
    
    RegBtn = static_cast<ui::Button*>(rootNode->getChildByName("Button_registered"));
	RegBtn->addTouchEventListener(CC_CALLBACK_2(GNS_LoginScene::BtnCallBack, this));
    RegBtn->setTag(REG_TAG_BTN);
	//RegBtn->setVisible(false);

// 	if (_tip == nullptr)
// 	{
// 		_tip = ImageView::create("loginloading.png");
// 		_tip->setPosition(Vec2(winsize.width / 2, StartBtn->getPositionY()));
// 		rootNode->addChild(_tip, 1000);
// 	}
// 	if (_mask == nullptr)
// 	{
// 		_mask = LayerColor::create(ccc4(0, 0, 0, 128));					//先加遮罩
// 		rootNode->addChild(_mask, 100);
// 	}

    RegYBtn = static_cast<ui::Button*>(rootNode1->getChildByName("Button_2"));
	RegYBtn->addTouchEventListener(CC_CALLBACK_2(GNS_LoginScene::BtnCallBack, this));
    RegYBtn->setTag(REG_TAG_Y);
    
    RegNBtn = static_cast<ui::Button*>(rootNode1->getChildByName("Button_1"));
	RegNBtn->addTouchEventListener(CC_CALLBACK_2(GNS_LoginScene::BtnCallBack, this));
    RegNBtn->setTag(REG_TAG_N);

	NameText = static_cast<TextField*>(rootNode->getChildByName("TextField_1"));
	NameText->addEventListener(CC_CALLBACK_2(GNS_YJFLayer::TextFileCallBack,this));
	NameText->setString(getUserName());

	PassText = static_cast<TextField*>(rootNode->getChildByName("TextField_2"));
	PassText->setString(getinUserPass());

	//GNS_Handler::createTMEditBoxWithExistFeild(NameText,rootNode);

	m_RegNameText = static_cast<TextField*>(rootNode1->getChildByName("TextField_1"));
	m_RegPassText = static_cast<TextField*>(rootNode1->getChildByName("TextField_2"));
	m_RegPhoneText = static_cast<TextField*>(rootNode1->getChildByName("TextField_3"));
	m_RegRecommendText = static_cast<TextField*>(rootNode1->getChildByName("TextField_4"));


	

	log("Login Scene Enter5");

	auto gusetBtn = static_cast<Button*>(rootNode->getChildByName("Button_1"));
	gusetBtn->setTag(BTN_GUSET);
	gusetBtn->addTouchEventListener(CC_CALLBACK_2(GNS_LoginScene::BtnCallBack,this));

	//auto Version = static_cast<Text*>(rootNode->getChildByName("Version"));
	
	//Version->setString(StringUtils::format("%d", GNS_PlayerMgr::getInstance()->getCurrentVersionClient()));

    return true;
}

void GNS_LoginScene::changeWnd(int tag)
{
	if (tag == REG_TAG_BTN)
	  {
		NameText->setScale(0);
		PassText->setScale(0);

		m_RegNameText->setScale(1); 
		m_RegPassText->setScale(1);
		m_RegPhoneText->setScale(1);
		m_RegRecommendText->setScale(1);
	}
	else
	{
		NameText->setScale(1);
		PassText->setScale(1);

		m_RegNameText->setScale(0);
		m_RegPassText->setScale(0);
		m_RegPhoneText->setScale(0);
		m_RegRecommendText->setScale(0);
	}
}


void GNS_LoginScene::onEnterTransitionDidFinish()
{
// 	if (_tip)
// 	{
// 		_tip->setVisible(false);
// 		_tip->removeFromParentAndCleanup(true);
// 	}
// 	if (_mask)
// 	{
// 		_mask->setVisible(false);
// 		_mask->removeAllChildrenWithCleanup(true);
// 	}
// 	if (!StartBtn->isVisible())
// 		StartBtn->setVisible(true);
// 	if (!RegBtn->isVisible())
// 		RegBtn->setVisible(true);
	if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
		AudioMgr::getInstance()->PlayMusic(10001,true);
	AudioMgr::getInstance()->setMusicVolume(0.5);
	AudioMgr::getInstance()->setEffectVolume(0.5);
	// 事件桥梁定时器
	IEventBridge::getInstance()->start();
	this->schedule(schedule_selector(GNS_LoginScene::OnEventBridge), 0.1f);
	m_isFinish = false;
}


void GNS_LoginScene::onExitTransitionDidStart()
{
	IEventBridge::getInstance()->stop();
	unschedule(schedule_selector(GNS_LoginScene::OnEventBridge));//关闭接收消息桥过来的定时器.
}

// 事件桥梁定时器的回调函数	  
void GNS_LoginScene::OnEventBridge(float dt)
{
	if (m_isFinish)
	{
		return;
	}
	IEventBridge::EVENT_INFO eventInfo;
	GnsClientFrame* pGnsClientFrame = GnsClientFrame::getInstance();
	assert(pGnsClientFrame);

	//判断帐号是否在其他地方登录
	if (GNS_PlayerMgr::GetInstance()->m_isKickout == true)
	{
		ShowCommonTips("您的帐号在其他地方登录！");
		GNS_PlayerMgr::GetInstance()->m_isKickout = false; //执行过之后要重置为false
	}
	//判断是否爆机
	if (GNS_PlayerMgr::GetInstance()->m_isBaoji == true)
	{
		ShowCommonTips("您已爆机，请联系客服！");
		GNS_PlayerMgr::GetInstance()->m_isBaoji = false; //执行过之后要重置为false
	}

	int iRes = 0;
	while (IEventBridge::getInstance()->popFront(eventInfo))
	{
		log("OnEventBridge");
		int mainCode = eventInfo.iMainCode;
		switch (mainCode)
		{
		case CLIENT_INNER_CONNECT:					// 连接结果
		{
			int& iReconnectCount = (int&)eventInfo.szBody;
			connectResult(eventInfo.iClientId, eventInfo.iSubCode, iReconnectCount);
			break;
		}
		case CLIENT_INNER_RE_CONNECT:			// 断线重连
		{
			int& iReconnectCount = (int&)eventInfo.szBody;
			reConnectResult(eventInfo.iClientId, eventInfo.iSubCode, iReconnectCount);
			break;
		}
		case CLIENT_INNER_RE_CLOSE:		// 断线
		{
			// 断线时不需要作任何处理，断线的事项交由断线重连功能（CLIENT_INNER_RE_CONNECT）进行处理
			break;
		}

		default:
			break;
		}
		int subCode = eventInfo.iSubCode;
		switch (subCode)
		{
			// 版本更新
		case SUB_SG_VERSION_REEOR:
		{
			CMD_VerError * pverError = (CMD_VerError*)eventInfo.szBody;
			log("服务器回：  版本错误！Version =%d ", pverError->iVersion);

			if (pverError->iVersion >= GNS_PlayerMgr::GetInstance()->getCurrentVersionClient())
			{
				 //版本号不一致，提示升级. 
				// this->Disconnect();
				 GNS_PlayerMgr::GetInstance()->setServerVersion(pverError->iVersion);

#if (CC_TARGET_PLATFORM==CC_PLATFORM_IOS) 
				//ios  
				 GNS_PlayerMgr::GetInstance()->setUpdateURL(pverError->szAppDownAddr);
#elif (CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID)
				// android  
				 GNS_PlayerMgr::GetInstance()->setUpdateURL(pverError->szAndrDownAddr);
				 log("下载地址 = %s",pverError->szAndrDownAddr);
#else  
				// win32  
				GNS_PlayerMgr::GetInstance()->setUpdateURL(pverError->szPCDownAddr);
#endif 
				  // 弹出升级提示框，强制升级
					showUpdate();
			 }

			 break;
		}
		case SUB_CSG_CONTACT_INFORMATION: //与官方的联系方式
		{
			GnsClientFrame* pGnsClientFrame = GnsClientFrame::getInstance();
			assert(pGnsClientFrame);
			CMD_ContactInformation *pContactInfo = (CMD_ContactInformation *)eventInfo.szBody;
			if (!pContactInfo || eventInfo.iBodyLen != sizeof(CMD_ContactInformation))
				  return;
			GNS_PlayerMgr::GetInstance()->SetContactInfo(*pContactInfo);

			pGnsClientFrame->closeSocket(LOGINSERVER);	  //断开登录服
			ShowServer();
			break;
		}
			// 注册
		case SUB_SC_USER_REGISTER_FINISH:
		{
 				CMD_CS_UserRegisterRet *pck = (CMD_CS_UserRegisterRet*)eventInfo.szBody;
				if (sizeof(CMD_CS_UserRegisterRet)!=eventInfo.iBodyLen)
				{
					return;
				}
 				if (pck->iRet != 0)
 				{
 					switch (pck->iRet)
 					{
 					case 20: ShowCommonTips("用户名已存在", true);
 						break;
					case 30: ShowCommonTips("用户昵称已存在", true);
 						break;
					case 40: ShowCommonTips("用户设备已存在", true);
 						break;
					case 50: ShowCommonTips("推荐人不存在", true);
 						break;
					case 60: ShowCommonTips("手机号码只能是数字", true);
						break;
					case 100:ShowCommonTips("推荐人错误", true);
 						break;
					case 130: ShowCommonTips("推荐码错误", true);
						break;
					case 140: ShowCommonTips("推荐码生成失败", true);
						break;
					case 150: ShowCommonTips("超过了层级限制", true);
						break;
 					default:
						ShowCommonTips("注册时出现异常,请联系客服!", true);
 						break;
 					};
 				}
 				break;
		}
			// 登录失败
		case SUB_SC_USER_LOGIN_FAIL:
		{
				CMD_SC_UserLoginFail *pck = (CMD_SC_UserLoginFail*)eventInfo.szBody;
				if (sizeof(CMD_SC_UserLoginFail)!= eventInfo.iBodyLen)
				{
					return;
				}
				if (pck->iRet == 0)
				   return;
				ShowCommonTips(GTOU(pck->szResText), true);
				break;
		}
		case SUB_CSG_PLAZA_LIST:		     //添加房间列表   启动器的房间只有一个
		{
			CMD_PlazaServerList *pSerVerInfo = (CMD_PlazaServerList *)eventInfo.szBody;
			
			if (!bRegist)
			{
				 ClientSocket* pHall = pGnsClientFrame->registClient(HALLSERVER, pSerVerInfo->szIp, pSerVerInfo->iPort);	//注册大厅服
				 assert(pHall);
				 if (!pHall)
					 break;
				 bRegist = true;
			}
			break;
		}
			// 房间列表完成
		case SUB_SC_USER_LOGIN_FINISH:
		{
				log("SUB_SC_USER_LOGIN_FINISH!");
				GnsClientFrame* pGnsClientFrame = GnsClientFrame::getInstance();
				assert(pGnsClientFrame);
				pGnsClientFrame->sendMsg(LOGINSERVER, MAIN_MSG_SYS, SUB_CSG_CONTACT_INFORMATION, 0, 0);

				CMD_PlazaServerList *pSerVerInfo = (CMD_PlazaServerList *)eventInfo.szBody;

				m_isFinish = true;
				IEventBridge::getInstance()->stop();
				unschedule(schedule_selector(GNS_LoginScene::OnEventBridge));//关闭接收消息桥过来的定时器.

				iRes = pGnsClientFrame->manualConnect(HALLSERVER);
				assert(0==iRes);
				if (0!=iRes)
					break;

				GNS_SceneMgr::getInstance()->replaceScene(SCENE_HALL);
				_hallScene =(GNS_HallScene*) GNS_SceneMgr::getInstance()->getSceneLayer(LAYER_HALL);
				break;
		}
			default:
			{
					   log("SIX_ClientLogin::HandlePacketLogin 未处理的消息, subCode=%d", subCode);
					   break;
			}

		}
		if (m_isFinish)
		{
			return;
		}
		int iTmp = 0;
	}
}

void GNS_LoginScene::BtnCallBack(Ref* pSender, ui::Widget::TouchEventType type)
{
    if (type==ui::Widget::TouchEventType::ENDED) {
        auto pButton = (Button *)pSender;
		int iRes = 0;
        int tag=pButton->getTag();
		GnsClientFrame* pGnsClientFrame = GnsClientFrame::getInstance();
		assert(pGnsClientFrame);
        switch (tag) {
			case BTN_SUBMIT_UPDATA:			//确认更新
			{
				OnUpdataSubmit();
				m_pUpdate->Show(false);
				break;
			}
			case BTN_QX_UPDATA:	       //取消更新
			{
				m_pUpdate->Show(false);
				break;
			}
			case BTN_GUSET:  //游客登录按钮
			{
				DoRegister(1);	  //1代表游客登录
				break;
			}
			case BTN_KEFU:	   //客服按钮
			{
				assert(pGnsClientFrame);
				
				log("manualConnect");
				iRes = GnsClientFrame::getInstance()->manualConnect(LOGINSERVER);
				assert(0 == iRes);
				pGnsClientFrame->sendMsg(LOGINSERVER, MAIN_MSG_SYS, SUB_CSG_CONTACT_INFORMATION, 0, 0);
				
				break;
			}

            case START_TAG_BTN:
            {
				if (!pGnsClientFrame->isClientSocketValid(LOGINSERVER))  //
				{
					log("manualConnect");
					iRes = GnsClientFrame::getInstance()->manualConnect(LOGINSERVER);
					assert(0 == iRes);
				}

				log("changeScene");
				changeScene();
				break;
            }
            case REG_TAG_BTN:
            {
                Node * StartNode = static_cast<Node *>(this->getChildByTag(10));
                StartNode->setVisible(false);
                Node * RegNode = static_cast<Node *>(this->getChildByTag(11));
                RegNode->setVisible(true);
				changeWnd(REG_TAG_BTN);
                break;
            }
            case REG_TAG_Y:
            {
				DoRegister();
				break;
            }
            case REG_TAG_N:
            {
                Node * RegNode = static_cast<Node *>(this->getChildByTag(11));
                RegNode->setVisible(false);
                
                Node * StartNode = static_cast<Node *>(this->getChildByTag(10));
                StartNode->setVisible(true);

				changeWnd(REG_TAG_N);
                break;
            }
            default:
                break;
        }
    }
}

void GNS_LoginScene::ShowServer()
{
	if (pServiceLayer == nullptr)
	{
		pServiceLayer = GNS_ServiceLayer::createLayer();
		pServiceLayer->SetNodeName("MainScenes/SeviceLayer.csb");
	}
	pServiceLayer->Show(true);
}

void GNS_LoginScene::showUpdate()
{
	if (!m_pUpdate)
	{
		string pErrorMsg;
		m_pUpdate = GNS_YJFLayer::createLayer("MainScenes/AgreeTipLayer.csb");
		
		auto btnSubmit = (Button*)m_pUpdate->m_RootNode->getChildByName("Button_1");
		btnSubmit->setTag(BTN_SUBMIT_UPDATA);
		btnSubmit->addTouchEventListener(CC_CALLBACK_2(GNS_LoginScene::BtnCallBack,this));

		auto qx = (Button*)m_pUpdate->m_RootNode->getChildByName("Button_2");
		qx->setTag(BTN_QX_UPDATA);
		qx->addTouchEventListener(CC_CALLBACK_2(GNS_LoginScene::BtnCallBack, this));
		int ver = GNS_PlayerMgr::GetInstance()->getServerVersion();
		// 显示文字提示
		if (ver == 0)
		{
			pErrorMsg = "当前游戏版本太旧，点击确定升级到最新版本！";
		}
		else
		{
			pErrorMsg = StringUtils::format("发现新版本[%d]，点击确认开始升级！",ver);
		}
		log("%s", pErrorMsg.c_str());
		Text *pText = (Text*)m_pUpdate->m_RootNode->getChildByName("Text_1");
		pText->setString(pErrorMsg);
	}
	m_pUpdate->Show(true);
}

void GNS_LoginScene::changeScene()
{
	GnsClientFrame* pGnsClientFrame = GnsClientFrame::getInstance();
	assert(pGnsClientFrame);
	CMD_CS_UserLogin pData;
	pData.iAppId = GLOBAL_GAME_ID;
	memcpy(pData.szName, NameText->getString().c_str(), NameText->getString().length());
	char PassWord[33] = { 0 };
	memcpy(PassWord, PassText->getString().c_str(), PassText->getString().length());
	memcpy(pData.szPwd, SystemMgr::getInstance()->md5String(PassWord), 33);
	pData.iPlatformNo = PLAT_PORM_NO;
	pData.iVersion = GNS_PlayerMgr::GetInstance()->getCurrentVersionClient();
	pData.iTrenchId = 0;

	// 获取设备码info
	string info;
	getDeviceInfo(info, 1023);
	if (info.length() <= 0)
	{
		ShowCommonTips("设备码异常");
		return;
	}

	// 计算md5=MD5(info)
	char md5[33] = { 0 };
	memset(&md5, 0, sizeof(md5));
	CCGnsOften::memcpy_safe(md5, 33, MD5Str((char*)info.c_str()), strlen(MD5Str((char*)info.c_str())));
	// 设备码
	memcpy(pData.szMachineCode, md5, strlen(md5));
	pData.szMachineCode[strlen(md5)] = 0;

	pGnsClientFrame->sendMsg(LOGINSERVER, MAIN_MSG_LOGIN, SUB_CS_USER_LOGIN, (char*)&pData, sizeof(pData));
	GNS_PlayerMgr::GetInstance()->setMyUserInfo((char*)pData.szName, (char*)PassWord, pData.szPwd, "");
	setUserName(NameText->getString());
	setUserPass(PassText->getString());
}


bool GNS_LoginScene::DoRegister(int type)
{
	CMD_CS_UserRegister pData;
	// 获取设备码info
	string info;
	auto name = m_RegNameText->getString();				//帐号
	auto pPass = m_RegPassText->getString();			//密码
	auto cellPhone = m_RegPhoneText->getString();		//手机号码
	auto pReferees = m_RegRecommendText->getString();   //推荐人
	if (type == 0)
	{
		// 用户名不能为空
		if (!name.length())
		{
			//this->showRegTips(
			ShowCommonTips("用户名不能为空");
			return false;
		}
		if (!(6 <= name.length() && name.length()<=14))
		{
			ShowCommonTips("用户名长度范围（6~14）");
			return false;
		}
		// 密码不能为空
		if (!pPass.length())
		{
			ShowCommonTips("密码不能为空");
			return false;
		}
		if (!CCGnsOften::isNoChinese(pPass))
		{
			ShowCommonTips("密码不能为中文");
		}
		if (!(6 <= pPass.length() && pPass.length() <= 14))
		{
			ShowCommonTips("密码长度范围(6~14)");
			return false;
		}
		if (!cellPhone.length())
		{
			ShowCommonTips("手机号码不能为空");
			return false;
		}
		if (!pReferees.length())
		{
			ShowCommonTips("推荐人不能为空");
			return false;
		}
	}
	
	if (type==1)
	{
		getDeviceInfo(info, 1023);
		if (info.length() <= 0)
		{
			ShowCommonTips("注册异常");
			return false;
		}
		log("................%s",info.c_str());
		// 计算md5=MD5(info)
		char md5[33] = { 0 };
		memset(&md5, 0, sizeof(md5));
		CCGnsOften::memcpy_safe(md5, 33, MD5Str((char*)info.c_str()), strlen(MD5Str((char*)info.c_str())));

		// 设备码
		memcpy(pData.szMachineCode, md5, strlen(md5));
		pData.szMachineCode[strlen(md5)] = 0;

		if (type == 1)
		{
			memcpy(pData.szName, md5, strlen(md5));
			pData.szName[strlen(md5)] = 0;

			memcpy(pData.szNickName, md5, strlen(md5));
			pData.szNickName[strlen(md5)] = 0;
		}
	}
	else
	{
		//注册也要机器码
		getDeviceInfo(info, 1023);
		if (info.length() <= 0)
		{
			ShowCommonTips("注册异常");
			return false;
		}
		log("................%s", info.c_str());
		// 计算md5=MD5(info)
		char md5[33] = { 0 };
		memset(&md5, 0, sizeof(md5));
		CCGnsOften::memcpy_safe(md5, 33, MD5Str((char*)info.c_str()), strlen(MD5Str((char*)info.c_str())));

		// 设备码
		memcpy(pData.szMachineCode, md5, strlen(md5));
		pData.szMachineCode[strlen(md5)] = 0;
	}


	GnsClientFrame* pGnsClientFrame = GnsClientFrame::getInstance();
	assert(pGnsClientFrame);
	if (!pGnsClientFrame->isClientSocketValid(LOGINSERVER))  //
	{
		GnsClientFrame::getInstance()->manualConnect(LOGINSERVER);
	}

	pData.iAppId = GLOBAL_GAME_ID;
	pData.iVersion = GNS_PlayerMgr::GetInstance()->getCurrentVersionClient();
	memcpy(pData.szName, m_RegNameText->getString().c_str(), m_RegNameText->getString().length());
	char PassWord[33] = { 0 };
	memcpy(PassWord, m_RegPassText->getString().c_str(), m_RegPassText->getString().length());
	memcpy(pData.szPwd, SystemMgr::getInstance()->md5String(PassWord), 33);
	pData.iPlatformNo = PLAT_PORM_NO;
	pData.iEnterMode = type;
	pData.iTrenchId = 0;
	memcpy(pData.szCellPhone, m_RegPhoneText->getString().c_str(), m_RegPhoneText->getString().length());
	memcpy(pData.szAgentCode, m_RegRecommendText->getString().c_str(), m_RegRecommendText->getString().length());
	pData.iRecommendCode = atoi(m_RegRecommendText->getString().c_str());
	pGnsClientFrame->sendMsg(0, MAIN_MSG_LOGIN, SUB_CS_USER_REGISTER, (char*)&pData, sizeof(pData));
	GNS_PlayerMgr::GetInstance()->setMyUserInfo((char*)pData.szName, (char*)PassWord, pData.szPwd, "");
	setUserName(m_RegNameText->getString());
	setUserPass(m_RegPassText->getString());
	return true;
}

bool GNS_LoginScene::OnUpdataSubmit()
{
	string pURL;
	int ver = GNS_PlayerMgr::GetInstance()->getServerVersion();
//#if (CC_TARGET_PLATFORM==CC_PLATFORM_WIN32)
	
//#elif (CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID)
	pURL =  GNS_PlayerMgr::GetInstance()->getUpdateURL();
	log("pURL[%s]", pURL.c_str());
	SystemMgr::getInstance()->runDownloadJNI(pURL.c_str());
#if (CC_TARGET_PLATFORM==CC_PLATFORM_IOS)
	// 只有企业开发者才可以使用itms-services做应用内置更新，无越狱要求限制。
	// Cool.Cat
	NSURL *pUpdateURL = 0;
	if (SIX_CCIOSHelper::GetInstance()->isJailBroken())
	{
		// iOS版本>=7.1，则使用ssl
		// 下面两种iOS版本判断方式均可
		//NSString *pIOSVersion = [[UIDevice currentDevice] systemVersion];
		//NSLog(@"iOS Version[%@][%d][%d]",pIOSVersion,__IPHONE_OS_VERSION_MIN_REQUIRED,__IPHONE_OS_VERSION_MAX_ALLOWED);
		//if ([pIOSVersion floatValue]>=7.1f)
		if (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_1)
		{
			pUpdateURL = [NSURL URLWithString : @"itms-services://?action=download-manifest&url=https://www.sysy365.com/ios/sysg.plist"];
		}
		// 否则老版本还是使用no ssl
		else
		{
			pUpdateURL = [NSURL URLWithString : @"itms-services://?action=download-manifest&url=http://www.sysy365.com/ios/sysg.plist"];
		}
	}
	// 个人开发者、公司开发者可以只能通过AppStore做应用外置更新。
	else
	{
		// sysg的itunes下载地址:)
		pUpdateURL = [NSURL URLWithString : @"https://itunes.apple.com/cn/app/id802835905"];
	}
	[[UIApplication sharedApplication] openURL:pUpdateURL];
#endif
	return true;
}

